% makestartset
% ============
%
% Parameters:
% -----------
% n 		Quantity patterns
% type		Pattern types, see description above
% seeplot	Boolean value, true if you want to see plot, else false
% [outputfile] 	Output filename for the pattern's plot (OPTIONAL)

% types		"x-uniform"
%		"random"
%		"selective"
%		"etc"
% Return:
% -------
%
% two data set P and T, P with input patterns and the 
% second one with test patterns


function [P, T]=makestartset( n, type, seeplot )

	LIM 	=2;
	LINF	=-LIM;
	LSUP	=LIM;
	STEP 	=(LSUP-LINF)/(2*n-1);

	i=1;
	
	switch(type)
		case "x-uniform"
			for v=LINF:STEP:LSUP
				if(mod(i,2)==0)
					P(i/2,:)=[v,fun(v)];
				else
					T(round(i/2),:)=[v,fun(v)];
				endif
				i=i+1;
			endfor

		case "random"
			v=LINF;

			T(1,:)=[0.5,0.5]; % BORRAR ESTO
			STEP=STEP *2 ;		% BORRAR ESTO

			
			do	
				P(i,:)=[v,fun(v)];
				step=rand*(0.5+0.5)-0.5;
				v=v+step;
				i=i+1;
				if(v>LSUP || v<LINF)
					v=LINF;
				endif
			until( i > n)		% 2n y los impares a test

		case "selective"
			
%  			T(1,:)=[0.5,0.5]; 	% BORRAR ESTO

			denso2=0.02/4;
			denso1=0.05/2;
			nodenso1=0.07/2;
			nodenso2=0.14/2;			
			
			% en los bordes esta repetido
			p(1,:)=[-2,-1.6]; 	% denso2
			p(2,:)=[-1.6,-1.1];	%	nodenso1
			p(3,:)=[-1.1,-0.6];	% denso1
			p(4,:)=[-0.6,0.5];	%	nodenso2 
			p(5,:)=[0.5,1.1];	% denso1
			p(6,:)=[1.1,1.6];	% 	nodenso1
			p(7,:)=[1.6,2];		% denso2

			for v=p(1,1):denso2:p(1,2)
				if(mod(i, 2) == 0)
				    T(i/2,:) = [v,fun(v)];
				else
				    P(round(i/2),:)=[v,fun(v)];
				endif
				i=i+1;
			endfor
			for v=p(2,1):nodenso1:p(2,2)
				if(mod(i, 2) == 0)
				    T(i/2,:) = [v,fun(v)];
				else
				    P(round(i/2),:)=[v,fun(v)];
				endif
				i=i+1;
			endfor
			for v=p(3,1):denso1:p(3,2)
				if(mod(i, 2) == 0)
				    T(i/2,:) = [v,fun(v)];
				else
				    P(round(i/2),:)=[v,fun(v)];
				endif
				i=i+1;
			endfor
			for v=p(4,1):nodenso2:p(4,2)
				if(mod(i, 2) == 0)
				    T(i/2,:) = [v,fun(v)];
				else
				    P(round(i/2),:)=[v,fun(v)];
				endif
				i=i+1;
			endfor
			for v=p(5,1):denso1:p(5,2)
				if(mod(i, 2) == 0)
				    T(i/2,:) = [v,fun(v)];
				else
				    P(round(i/2),:)=[v,fun(v)];
				endif
				i=i+1;
			endfor
			for v=p(6,1):nodenso1:p(6,2)
				if(mod(i, 2) == 0)
				    T(i/2,:) = [v,fun(v)];
				else
				    P(round(i/2),:)=[v,fun(v)];
				endif
				i=i+1;
			endfor
			for v=p(7,1):denso2:p(7,2)
				if(mod(i, 2) == 0)
				    T(i/2,:) = [v,fun(v)];
				else
				    P(round(i/2),:)=[v,fun(v)];
				endif
				i=i+1;
			endfor

	endswitch


	printf("cantidad de patrones: %d\n",rows(P));
	printf("cantidad de test: %d\n",rows(T));

	if( seeplot )
		plot(P(:,1),P(:,2),"*b;ENTRADA;",T(:,1),T(:,2),"+r;TEST;");
		mytitle=sprintf("PATRONES DE ENTRADA Y TEST \n(tipo: %s)",type);
		title(mytitle);
		xlabel("x")
		ylabel("Funcion 12: f(x) = sinh(x)cos(x^2)");
		print -djpg patrones;
	endif

endfunction



function ans=fun(X)
	ans=sinh(X)'.*cos(X.^2);
endfunction

function ans=funDer(X)
	ans=cos(X.^2).*cosh(X)-2*X.*sinh(X);
endfunction
